const { Deferrable, DataTypes } = require('sequelize')
const sequelize = require('../db/sequelize')
const Question = require('./question.model')
const User = require('./user.model')

const Result = sequelize.define('result', {
  answerer: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'id',
      deferrable: Deferrable.INITIALLY_IMMEDIATE
    },
    comment: '回答者的 userId'
  },
  questionId: {
    type: DataTypes.INTEGER,
    references: {
      model: Question,
      key: 'id',
      deferrable: Deferrable.INITIALLY_IMMEDIATE
    },
    comment: '问题的id'
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: '问题的答案'
  },
  weight: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '根据用户评星增加权重'
  }
}, {
  charset: 'utf8'
})

module.exports = Result
